"""
#!!===========================================================
#版权（C）2023, Huawei Technologies Co., HUTAF xDevice
#!!===========================================================
#文 件 名:      SecurityUserIamPinAuthApi.py
#文件说明:      PIN码相关公共AW
#作   者:
#生成日期:
#!!===========================================================
"""

# -*- coding: utf-8 -*-
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import keyword
from aw.Useriam.PinAuth import SecurityUserIamCommon


@keyword
def setPIN(oh_device, pin, pin_type=0):
    """
    #======================================================================
    #   @Method:           setPIN(oh_device, pin)
    #   @Precondition:     手机未设置PIN码,亮屏且在主页面
    #   @Func:             首次录入pin码后，锁屏进行解锁
    #   @Param:             pin：设置的PIN码
    #   @Param:             pin_type: 0：6位数字密码,1：自定义数字密码,2：混合密码。默认值为0
    #   @Example:
    #======================================================================
    """
    SecurityUserIamCommon.enterPinSetting(oh_device)
    CommonOH.touchByText(oh_device, "锁屏密码")
    if pin_type == 0:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
    elif pin_type == 1:
        CommonOH.touchByText(oh_device, "其他密码类型")
        CommonOH.touchByText(oh_device, "自定义数字密码")
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "继续")
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    elif pin_type == 2:
        CommonOH.touchByText(oh_device, "其他密码类型")
        CommonOH.touchByText(oh_device, "混合密码")
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "继续")
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    else:
        print("您输入的type错误，请输入正确的type值")
        return False


@keyword
def unlockPIN(oh_device, pin, pin_type=0):
    """
    #======================================================================
    #   @Method:           unlockPIN(oh_device, pin)
    #   @Precondition:     手机处于锁屏状态
    #   @Func:             锁屏后，按power键执行PIN码解锁
    #   @Param:             pin：设置的PIN码
    #   @Param:             pin_type: 0：6位数字密码,1：自定义数字密码,2：混合密码。默认值为0
    #   @Example:
    #======================================================================
    """
    CommonOH.wake(oh_device)
    CommonOH.checkScreenStatus(oh_device)
    if pin_type == 0:
        CommonOH.touchByText(oh_device, text=pin[0])
        CommonOH.touchByText(oh_device, text=pin[1])
        CommonOH.touchByText(oh_device, text=pin[2])
        CommonOH.touchByText(oh_device, text=pin[3])
        CommonOH.touchByText(oh_device, text=pin[4])
        CommonOH.touchByText(oh_device, text=pin[5])
    elif pin_type == 1:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确认")
    elif pin_type == 2:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确认")
    else:
        print("您输入的type错误，请输入正确的type值")
        return False


@keyword
def deletePIN(oh_device, pin, pin_type=0):
    """
    #======================================================================
    #   @Method:           deletePIN(oh_device, pin)
    #   @Precondition:     手机设置了PIN码，并已解锁亮屏
    #   @Func:             删除PIN码
    #   @Param:             pin：设置的PIN码
    #   @Param:             pin_type: 0：6位数字密码,1：自定义数字密码,2：混合密码。默认值为0
    #   @Example:
    #======================================================================
    """
    SecurityUserIamCommon.enterPinSetting(oh_device)
    CommonOH.touchByText(oh_device, "关闭锁屏密码")
    CommonOH.touchByText(oh_device, "关闭")
    if pin_type == 0:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "下一步")
    elif pin_type == 1:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "下一步")
    elif pin_type == 2:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "下一步")
    else:
        print("您输入的type错误，请输入正确的type值")
        return False
